import 'package:shared_preferences/shared_preferences.dart';
import '../../core/utils/logging.dart';

class AppPrefs {
  SharedPreferences? _prefs;

  Future<void> initSharedPrefs() async {
    _prefs ??= await SharedPreferences.getInstance();
  }

  Future<void> saveHomePageMenuIndex(int value) async {
    try {
      await initSharedPrefs();
      await _prefs!.setInt('homeMenuIndex', value);
    } catch (e) {
      logger.i('Error home menu index: $e');
    }
  }

  Future<int> loadHomePageMenuIndex() async {
    try {
      await initSharedPrefs();
      int meneIndex = _prefs!.getInt('homeMenuIndex') ?? 0;
      return meneIndex;
    } catch (e) {
      logger.i('Error loading home menu index: $e');
      return 0;
    }
  }
}
